package io.github.heollhai.common.utils;

import io.github.heollhai.common.entity.vo.common.keyValue.KeyValuePair;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author: lmf
 * @Create: 2024/10/8 9:16
 * Description: map公共操作工具类
 */
public class MapUtils {

    /**
     * 将map集合装换为 KeyValuePair 对象
     */
    public static <K, V> List<KeyValuePair<K, V>> toKeyValuePair(Map<K, List<V>> map) {
        return map.entrySet().stream()
                .map(entry -> {
                    KeyValuePair<K, V> kvKeyValuePair = new KeyValuePair<>();
                    kvKeyValuePair.setValue(entry.getValue());
                    kvKeyValuePair.setKey(entry.getKey());
                    return kvKeyValuePair;

                })
                .collect(Collectors.toList());
    }
}
